<template>
  <div class="app-container">


    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['tc:TcMemberLevel:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['tc:TcMemberLevel:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['tc:TcMemberLevel:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['tc:TcMemberLevel:export']"
        >导出</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="TcMemberLevelList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
                  <el-table-column label="置顶折扣/月(1-100/100)" align="center" prop="id" />
                  <el-table-column label="会员价/月" align="center" prop="price" />
                  <el-table-column label="等级名称" align="center" prop="name" />
                  <el-table-column label="招聘免费发布数/月" align="center" prop="jobCount" />
                  <el-table-column label="房源免费发布数/月" align="center" prop="roomCount" />
                  <el-table-column label="车辆免费发布数/月" align="center" prop="carCount" />
                  <el-table-column label="物品免费发布数/月" align="center" prop="goodsCount" />
                  <el-table-column label="农林免费发布数/月" align="center" prop="nongCount" />
                  <el-table-column label="生意免费发布数/月" align="center" prop="businessCount" />
                  <el-table-column label="推广免费发布数/月" align="center" prop="smsCount" />
                  <el-table-column label="打听免费发布数/月" align="center" prop="speakCount" />
                  <el-table-column label="车找人免费发布数/月:" align="center" prop="carToPeopleCount" />
                  <el-table-column label="人找车免费发布数/月" align="center" prop="peopleToCarCount" />
                  <el-table-column label="超过免费发布数价格/条" align="center" prop="moreCount" />
                  <el-table-column label="置顶折扣/月(1-100/100)" align="center" prop="topCount" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['tc:TcMemberLevel:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['tc:TcMemberLevel:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改vip等级对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
                                                            <el-form-item label="会员价/月" prop="price">
          <el-input v-model="form.price" placeholder="请输入会员价/月" />
        </el-form-item>
                                                                    <el-form-item label="等级名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入等级名称" />
        </el-form-item>
                                                                    <el-form-item label="招聘免费发布数/月" prop="jobCount">
          <el-input v-model="form.jobCount" placeholder="请输入招聘免费发布数/月" />
        </el-form-item>
                                                                    <el-form-item label="房源免费发布数/月" prop="roomCount">
          <el-input v-model="form.roomCount" placeholder="请输入房源免费发布数/月" />
        </el-form-item>
                                                                    <el-form-item label="车辆免费发布数/月" prop="carCount">
          <el-input v-model="form.carCount" placeholder="请输入车辆免费发布数/月" />
        </el-form-item>
                                                                    <el-form-item label="物品免费发布数/月" prop="goodsCount">
          <el-input v-model="form.goodsCount" placeholder="请输入物品免费发布数/月" />
        </el-form-item>
                                                                    <el-form-item label="农林免费发布数/月" prop="nongCount">
          <el-input v-model="form.nongCount" placeholder="请输入农林免费发布数/月" />
        </el-form-item>
                                                                    <el-form-item label="生意免费发布数/月" prop="businessCount">
          <el-input v-model="form.businessCount" placeholder="请输入生意免费发布数/月" />
        </el-form-item>
                                                                    <el-form-item label="推广免费发布数/月" prop="smsCount">
          <el-input v-model="form.smsCount" placeholder="请输入推广免费发布数/月" />
        </el-form-item>
                                                                    <el-form-item label="打听免费发布数/月" prop="speakCount">
          <el-input v-model="form.speakCount" placeholder="请输入打听免费发布数/月" />
        </el-form-item>
                                                                    <el-form-item label="车找人免费发布数/月:" prop="carToPeopleCount">
          <el-input v-model="form.carToPeopleCount" placeholder="请输入车找人免费发布数/月:" />
        </el-form-item>
                                                                    <el-form-item label="人找车免费发布数/月" prop="peopleToCarCount">
          <el-input v-model="form.peopleToCarCount" placeholder="请输入人找车免费发布数/月" />
        </el-form-item>
                                                                    <el-form-item label="超过免费发布数价格/条" prop="moreCount">
          <el-input v-model="form.moreCount" placeholder="请输入超过免费发布数价格/条" />
        </el-form-item>
                                                                    <el-form-item label="置顶折扣/月(1-100/100)" prop="topCount">
          <el-input v-model="form.topCount" placeholder="请输入置顶折扣/月(1-100/100)" />
        </el-form-item>
                  </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTcMemberLevel, getTcMemberLevel, delTcMemberLevel, addTcMemberLevel, updateTcMemberLevel, exportTcMemberLevel } from "@/api/tc/TcMemberLevel";

export default {
  name: "TcMemberLevel",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // vip等级表格数据
      TcMemberLevelList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
                                                                                                                                                                                          // 查询参数
      queryParams: {
        pageNum: 0,
        pageSize: 10,
                price: undefined,
                name: undefined,
                jobCount: undefined,
                roomCount: undefined,
                carCount: undefined,
                goodsCount: undefined,
                nongCount: undefined,
                businessCount: undefined,
                smsCount: undefined,
                speakCount: undefined,
                carToPeopleCount: undefined,
                peopleToCarCount: undefined,
                moreCount: undefined,
                topCount: undefined
          },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
                                                                  }
    };
  },
  created() {
    this.getList();
                                                              },
  methods: {
    /** 查询vip等级列表 */
    getList() {
      this.loading = true;
      listTcMemberLevel(this.queryParams).then(response => {
        this.TcMemberLevelList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
                                                                // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
            id: undefined,
                price: undefined,
                name: undefined,
                jobCount: undefined,
                roomCount: undefined,
                carCount: undefined,
                goodsCount: undefined,
                nongCount: undefined,
                businessCount: undefined,
                smsCount: undefined,
                speakCount: undefined,
                carToPeopleCount: undefined,
                peopleToCarCount: undefined,
                moreCount: undefined,
                topCount: undefined
          };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 0;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加vip等级";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getTcMemberLevel(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改vip等级";
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateTcMemberLevel(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addTcMemberLevel(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除vip等级编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delTcMemberLevel(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有vip等级数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportTcMemberLevel(queryParams);
        }).then(response => {
          this.download(response.data);
        }).catch(function() {});
    }
  }
};
</script>
